#include "dragable_item.h"
#include <QDebug>

DragablePixmapItem::DragablePixmapItem(QGraphicsItem *parent)
    : QObject(), QGraphicsPixmapItem(parent), m_isWorn(false)
{
    setFlag(ItemIsMovable);
    setFlag(ItemSendsGeometryChanges);
    setAcceptHoverEvents(true);
}

DragablePixmapItem::DragablePixmapItem(const QString& name, QGraphicsItem *parent)
    : QObject(), QGraphicsPixmapItem(parent), m_name(name), m_isWorn(false)
{
    setFlag(ItemIsMovable);
    setFlag(ItemSendsGeometryChanges);
    setAcceptHoverEvents(true);
}

QString DragablePixmapItem::name() const
{
    return m_name;
}
void DragablePixmapItem::setWorn(bool worn)
{
    m_isWorn = worn;
}
bool DragablePixmapItem::isWorn() const
{
    return m_isWorn;
}
QVariant DragablePixmapItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
    if (change == ItemPositionHasChanged)
    {
        emit positionChanged(this);
    }
    return QGraphicsPixmapItem::itemChange(change, value);
}
void DragablePixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
    emit hovered(true);
    QGraphicsPixmapItem::hoverEnterEvent(event);
}

void DragablePixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
    emit hovered(false);
    QGraphicsPixmapItem::hoverLeaveEvent(event);
}

void DragablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    qDebug() << "鼠标按下:" << m_name;
    QGraphicsPixmapItem::mousePressEvent(event);
}

void DragablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    qDebug() << "鼠标释放:" << m_name;
    QGraphicsPixmapItem::mouseReleaseEvent(event);
}
